package ui.components;

import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.JFrame;

public class ImageLoader extends JFrame {

	public Image read( String file ) {
		/*
		BufferedImage bufferedimg = null;
		File f = new File( file );
		
		try {
			bufferedimg = ImageIO.read( f );
		} catch (IOException e) {
			System.err.println( "Failed to load image " + file );
		}
		return Toolkit.getDefaultToolkit( ).createImage( bufferedimg.getSource( ) );
		*/
		
		String path = file;
		URL url = Thread.currentThread().getContextClassLoader().getResource( path);
		BufferedImage bufferedimg = null;
		
		try {
			bufferedimg = ImageIO.read( url );
		} catch (IOException e) {
			System.err.println( "Failed to load image " + file );
			System.exit( 1 );
		}
		return Toolkit.getDefaultToolkit( ).createImage( bufferedimg.getSource( ) );
		
	}

}
